
// 1 sequence for scaning
// 
// .. 
CActionSeq = function() {
	this.class_ActionSeq = 1;
	this.objName = 'CActionSeq : ';
};


CActionSeq.DA_INVALID = 9;


CActionSeq.prototype = {


	setAction: function(action) {
		this.action = action;
		
		// define stage 
		this.action_stage = action.action_table;
		
		// set targt
		//this.setTgt(ta_param);
		// this.param = action.param;
	},
	
	// action �먯꽌 諛쏆븘��,   seq 泥섎━. 
	start: function() {

		debug.log(this, ' :' + this.action.name);
		debug.log(this, '\r\n :' + this.action.name);
		debug.log(this, ' : \r\n' + this.action.name);
		debug.log(this, ' :' + this.action.name , '----------------------');

			// start 1st action 
		this.next_action_idx = -1;		// reset index 
		this.goNextAction();
	},
	

	next: function() {
		this.goNextAction();
	},

	donextTimeout: function(timeout) {
		var self = this;
		 setTimeout( function() { self.goNextAction.call(self); } ,CUtil.RandTime(timeout));	
	},


	/*
		
	// action CB 에서  다음 action param 을 지정. 
	//*/
	setDoParam: function(actionname, param) {
		//And the same thing using ES5's Array methods:
		var stage = CUtil.findActionByCmd(this.action_stage, actionname);
		if ( ! stage ) {
			debug.log(this,3, ' Not Exist Action !!!' , actionname);
			return;
		}
		$.extend(true, stage.doParam, param);
		debug.log(this,2, stage.doParam);
	},
	
	
	// re try cur actioin 
	retryCurAction: function(actionname) {
		//And the same thing using ES5's Array methods:
		var stage = CUtil.findActionByCmd(this.action_stage, actionname);
		// back to prev .. 
		this.next_action_idx  -= 1;
		debug.log(this, ' retry actionname',  stage.doParam);
	},
	
	// skip next action 
	skipNextAction: function() {
		//And the same thing using ES5's Array methods:
		// var stage = CUtil.findActionByCmd(this.action_stage, actionname);
		// back to prev .. 
		this.next_action_idx  += 1;
		// debug.log(this, ' skipNextAction  actionname',  stage.doParam);
	},
	
	goNextAction: function() {
				// go next 
		this.next_action_idx += 1; 
			
		// done complete!
		if ( this.next_action_idx >= this.action_stage.length ) {
			debug.log(this, retName(this), ' Done Action Seq!! ');
			
			// old cb.
		// if ( this.param && this.param.success_cb ) 
			// this.param.success_cb();
			
			// new complete cb
			if ( this.action.done_cb)  {
				this.action.done_cb();
			}
			return;
		}
		
		var outer = this;
		var stage = this.action_stage[ this.next_action_idx ];
		var aAction = stage.doFunc;
		var aParam = stage.doParam;
		var cb = stage.cb;

		debug.log(this, retName(this), stage.cmd  , stage.cmd , ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~', stage.cmd,  ' start!! ' );
		debug.log(this, retName(this), stage.cmd  +   '  start!! '
			,aAction , aParam);


		var ret = 0;
		// function is string - helper ..
		 
		if (typeof aAction === 'string') {
			
			ret = em.ahelper[ aAction ].call( em.ahelper, aParam );

			// var helper_str = 'em.ahelper'; 
			// eval( helper_str +'.'+ aAction + '.call(' + helper_str + ', aParam)' );
			// em.ahelper.+aAction.call(em.ahelper, aParam);
		} else {
			ret = aAction.call(this.action.context, aParam, cb);
		}
		 
		/// error abort . stop  
		// !!! this is not ret of cb... just do cmd fn return.!!!! 
		//  in cb : go next or cll don_cb. explictly...
		if ( ret == -1 ) {
			debug.log( this, ' Error in data CB::: abort action seq : return...', ret, aAction, aParam);
			if ( this.action.done_cb)  {
				this.action.done_cb();
			}
			return;
		}		 
	},

	initialize: function(actions) {

	},
		

};



